package cn.schoolwow.util.domain.compare.instanceList;

import cn.schoolwow.util.module.compare.instanceList.domain.CompareInstanceListQueryOption;
import org.apache.commons.lang3.Validate;

import java.util.List;

public class CompareInstanceList<T> {
    private CompareInstanceListQueryOption<T> compareInstanceListQueryOption = new CompareInstanceListQueryOption();

    /**创建实例查询*/
    public static CompareInstanceList newInstance(){
        CompareInstanceList compareInstanceList = new CompareInstanceList();
        return compareInstanceList;
    }

    /**设置修改前的列表*/
    public CompareInstanceList<T> beforeInstanceList(List<T> beforeInstanceList){
        compareInstanceListQueryOption.beforeInstanceList = beforeInstanceList;
        return this;
    }

    /**设置修改后的列表*/
    public CompareInstanceList<T> afterInstanceList(List<T> afterInstanceList){
        compareInstanceListQueryOption.afterInstanceList = afterInstanceList;
        return this;
    }

    /**检查是否新增时的唯一字段*/
    public CompareInstanceList<T> addCheckFieldNames(String[] addCheckFieldNames){
        compareInstanceListQueryOption.addCheckFieldNames = addCheckFieldNames;
        return this;
    }

    /**检查是否更新时的唯一字段*/
    public CompareInstanceList<T> updateCheckFieldNames(String[] updateCheckFieldNames){
        compareInstanceListQueryOption.updateCheckFieldNames = updateCheckFieldNames;
        return this;
    }

    public CompareInstanceListResponse<T> execute(){
        Validate.notNull(compareInstanceListQueryOption.beforeInstanceList, "修改前的列表不能为空");
        Validate.notNull(compareInstanceListQueryOption.afterInstanceList, "修改后的列表不能为空");
        Validate.notNull(compareInstanceListQueryOption.addCheckFieldNames, "检查是否新增时的唯一字段不能为空");
        Validate.notNull(compareInstanceListQueryOption.updateCheckFieldNames, "检查是否更新时的唯一字段不能为空");
        return new CompareInstanceListResponse<T>(compareInstanceListQueryOption);
    }
}
